﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using SuperFind.Lib.Core;
using SuperFind.Lib.Data;

namespace SuperFind
{
    /// <summary>
    /// Interaction logic for Option.xaml
    /// </summary>
    public partial class Option : Window
    {
        public Option()
        {
            InitializeComponent();
        }
        public Option(int selectedTabIndex)
        {
            InitializeComponent();
            tbcOptions.SelectedIndex = selectedTabIndex;
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            List<DiskInfo> diskInfo = Disk.DiscoverAttachedDisks();
            lstSelectedLocations.ItemsSource = diskInfo;
            LoadSettings(diskInfo);
            
        }
        private void LoadSettings(List<DiskInfo> diskInfo)
        {
            Settings settings = new Settings();
            List<string> locations = settings.LoadLocations();
            if (locations != null)
            {
                foreach (DiskInfo info in diskInfo)
                {
                    if (locations.Contains(info.RootDirectory))
                    {
                        lstSelectedLocations.SelectedItems.Add(info);
                    }
                }
            }
        }
        public void SaveSettings()
        {
            /*
             * The lines below had logical errors.
             * Please check and try to understand those errors.
             * I have corrected the errors. But it is necessary to
             * understand our own errors.
             * 
             * */
            //DataRetrive objDataRetrive = new DataRetrive();
            //objDataRetrive.selectedField = GetSelectedListItems();
            //objDataRetrive.GetData();


            Settings settings = new Settings();
            settings.Save(GetSelectedListItems());
        }
        public List<string> GetSelectedListItems()
        {
            List<string> selectedListItems = new List<string>();
            foreach (DiskInfo selectedFolder in lstSelectedLocations.SelectedItems)
            {
                selectedListItems.Add(selectedFolder.RootDirectory);
            }
            return selectedListItems;
        }
        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
        }
    }
}
